package com.qf.limit.commons.utils;

import com.qf.limit.commons.exception.ServiceException;
import com.qf.limit.commons.r.Codes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UserUtils {

    public static Integer getUid() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String token = request.getHeader("Token");
        Integer uid = JwtUtils.parseJwtToken(token,"id");
        if (uid == null) {
            throw new ServiceException(Codes.CODE_ERROR);

        }
        return uid;
    }
}
